import { Http } from "@/utils/request";
import { Toast } from "@/utils/toast";
import { delayTask } from "@/utils/timer";

const baseUrl = "/favorite";

export const add_cancel_favorite_api = (
  data: { favId: string; type: number; status: 1 | 2 }, // type：1：景区；17：课程；20：展览；21：视频
  showError = true
) => {
  return Http.post(`${baseUrl}/add_cancel_favorite`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const mini_fav_type_list_api = (showError = true) => {
  return Http.get<MiniApp.PagingData>(`${baseUrl}/mini_fav_type_list`).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};

export const list_api = (
  data: { type: number } & MiniApp.PagingQuery,
  showError = true
) => {
  return Http.get<MiniApp.PagingData>(`${baseUrl}/list`, data).catch(
    (error: Error) => {
      showError && delayTask(60, () => Toast.show(error.message));
      return Promise.reject(error);
    }
  );
};
